package com.frame.work.service.impl;

import com.frame.work.entity.ProductInfoApp;
import com.frame.work.mapper.ProductInfoAppMapper;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


/**
 * @author wjming
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TblDeviceTypeService extends ServiceImpl<ProductInfoAppMapper, ProductInfoApp> {
    private final ProductInfoAppMapper productInfoAppMapper;

    /**
     * 多功能开关
     */
    private static final String DEVICE_0FAA8A09 = "0FAA8A09";
    /**
     * 卓悦面板
     */
    private static final String DEVICE_0FAA8A0A = "0FAA8A0A";
    /**
     * 特殊符号
     */
    private static final String Z_Z_T_S = "_";

    public ProductInfoApp getOneById(String deviceType) {
        String prodType = null;
        if (StringUtils.indexOf(deviceType, Z_Z_T_S) > 0) {
            prodType = StringUtils.substring(deviceType, 0, deviceType.indexOf(Z_Z_T_S));
        } else {
            prodType = deviceType;
        }
        ProductInfoApp productInfoApp = productInfoAppMapper.selectDeviceTypeMessage(prodType);
        if (productInfoApp == null) {
            ProductInfoApp productInfoApp1 = new ProductInfoApp();
            productInfoApp1.setPZUrl("");
            productInfoApp1.setProductName("未知设备");
            return productInfoApp1;
        }
        //判断是否是多功能开关
        if (StringUtils.equals(DEVICE_0FAA8A09, productInfoApp.getProductType()) ||
                StringUtils.equals(DEVICE_0FAA8A0A, productInfoApp.getProductType())) {
            productInfoApp.setProductName(productInfoApp.getProductType() + "(场景)");
        }
        int indexOf = deviceType.indexOf("_");
        if (indexOf > 0) {
            String way = StringUtils.substring(deviceType, indexOf);
            //若是智能空调面板
            if (StringUtils.equals("0FAC0502", StringUtils.substring(deviceType, 0, deviceType.indexOf(Z_Z_T_S)))) {
                switch (way) {
                    case "_1":
                        productInfoApp.setProductName("空调面板");
                        break;
                    case "_2":
                        productInfoApp.setProductName("地暖面板");
                        break;
                    case "_3":
                        productInfoApp.setProductName("新风面板");
                        break;
                    default:
                        break;
                }
            } else {
                productInfoApp.setProductName(productInfoApp.getProductName() + way);
            }
        }

        return productInfoApp;
    }
}
